/*
 * Created by JFormDesigner on Thu Jul 04 01:56:32 CST 2024
 */

package scct.ZhuZhouXing.ui;

import jdk.nashorn.internal.scripts.JO;
import scct.ZhuZhouXing.dao.UserDao;

import java.awt.*;
import java.awt.event.*;
import java.util.Objects;
import javax.swing.*;

/**
 * @author xzy
 */
public class SignUp extends JDialog {
    public SignUp(Window owner) {
        super(owner);
        initComponents();
    }

    private void btnSignUp(ActionEvent e) {
        String Name=txtName.getText();
        String Pass=txtPass.getText();
        String PassWord=txtpassword.getText();
        if (Objects.equals(PassWord, Pass)){
            UserDao userDao=new UserDao();
            if (userDao.addUser(Name,Pass)){
                JOptionPane.showMessageDialog(this,"注册成功！");
                this.dispose();
            }
        }else {
            JOptionPane.showMessageDialog(this,"注册失败，可能密码不匹配！");
            return;
        }
        //注册
        
    }

    private void btncli(ActionEvent e) {
        this.dispose();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - 老登
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        btnSignUp = new JButton();
        btncli = new JButton();
        txtName = new JTextField();
        txtPass = new JTextField();
        txtpassword = new JTextField();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 7f));
        label1.setText("SignUp");
        contentPane.add(label1);
        label1.setBounds(175, 25, 120, 35);

        //---- label2 ----
        label2.setText("\u5bc6\u7801");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 3f));
        contentPane.add(label2);
        label2.setBounds(110, 105, 45, 20);

        //---- label3 ----
        label3.setText("\u786e\u8ba4\u5bc6\u7801");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 3f));
        contentPane.add(label3);
        label3.setBounds(85, 140, 70, 20);

        //---- label4 ----
        label4.setText("\u8d26\u53f7");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 3f));
        contentPane.add(label4);
        label4.setBounds(110, 70, 45, 20);

        //---- btnSignUp ----
        btnSignUp.setText("\u6ce8\u518c");
        btnSignUp.addActionListener(e -> btnSignUp(e));
        contentPane.add(btnSignUp);
        btnSignUp.setBounds(new Rectangle(new Point(100, 195), btnSignUp.getPreferredSize()));

        //---- btncli ----
        btncli.setText("\u53d6\u6d88");
        btncli.addActionListener(e -> btncli(e));
        contentPane.add(btncli);
        btncli.setBounds(new Rectangle(new Point(230, 195), btncli.getPreferredSize()));
        contentPane.add(txtName);
        txtName.setBounds(160, 70, 150, 25);
        contentPane.add(txtPass);
        txtPass.setBounds(160, 105, 150, 25);
        contentPane.add(txtpassword);
        txtpassword.setBounds(160, 140, 150, 25);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(400, 300);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - 老登
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JButton btnSignUp;
    private JButton btncli;
    private JTextField txtName;
    private JTextField txtPass;
    private JTextField txtpassword;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
